﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DAL.Repositories;
using ggHD.Domain.BizObj;
using ggHD.Domain.Repisitories;
using LinqToDB;

namespace ggHD.DAL.Repositories
{
    internal class ExternalInitiatorRepository : Repository<ExternalInitiator, int>, IExternalInitiatorRepository
    {
        public ExternalInitiatorRepository(IDataContext context)
            : base(context)
        {
        }

        public int Insert(ExternalInitiator entity, bool checkForUnique)
        {
            if (Select(a => a.FromAddress == entity.FromAddress.ToLower()).Any())
                return 0;

            return Insert(entity);
        }

        public override int Insert(ExternalInitiator entity)
        {
            var copy = entity;
            copy.FromAddress = copy.FromAddress.ToLower();
            return base.Insert(copy);
        }
    }
}
